package com.liang.semaphore;

import java.util.concurrent.Semaphore;

public class MySemaphoreDemo implements Runnable{
    private Semaphore sp = new Semaphore(2);

    @Override
    public void run() {
        try {
            Thread.sleep(1000);
            sp.acquire();
            System.out.println(Thread.currentThread().getName()+"正在执行");
            System.out.println("执行完了");

        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            sp.release();
        }
    }
}
